//
//  HOMNSSetSelectSingleWhereTests.m
//  HigherOrderMessaging
//
//  Created by Ofri Wolfus on 14/10/06.
//  Copyright 2006 Ofri Wolfus. All rights reserved.
//

#import "HOMNSSetSelectSingleWhereTests.h"


@implementation HOMNSSetSelectSingleWhereTests

- (id)init {
	if ((self = [super init])) {
		int i;
		
		msg1 = [MSG(hasPrefix:@"b") retain];
		msg2 = [MSG(hasPrefix:@"9999") retain];
	}
	
	return self;
}

- (void)dealloc {
	[msg1 release]; msg1 = nil;
	[msg2 release]; msg2 = nil;
	[super dealloc];
}

#pragma mark -
#pragma mark Small Set Tests

- (id)testSmallSet {
	return [smallSet selectSingleWhere:MSG(hasPrefix:@"b"), nil];
}

- (id)testSmallSet_CachedMessage {
	return [smallSet selectSingleWhere:msg1, nil];
}

- (id)testSmallSet_NSEnumerator {
	NSEnumerator *e = [smallSet objectEnumerator];
	NSString *str;
	
	while ((str = [e nextObject])) {
		if ([str hasPrefix:@"b"])
			return str;
	}
	
	return nil;
}

#pragma mark -
#pragma mark Large Set Tests

- (id)testLargeSet {
	return [largeSet selectSingleWhere:MSG(hasPrefix:@"9999"), nil];
}

- (id)testLargeSet_CachedMessage {
	return [largeSet selectSingleWhere:msg2, nil];
}

- (id)testLargeSet_NSEnumerator {
	NSEnumerator *e = [largeSet objectEnumerator];
	NSString *str;
	
	while ((str = [e nextObject])) {
		if ([str hasPrefix:@"9999"])
			return str;
	}
	
	return nil;
}

#pragma mark -
#pragma mark Tests Verification

- (BOOL)verifyResult:(NSString *)str ofTest:(SEL)sel {
	NSString *name = NSStringFromSelector(sel);
	
	if ([name hasPrefix:@"testSmallSet"]) {
		DPTestAssert([str isEqualToString:@"b"], @"The returned string is not equal to 'b'. Returned string = %@", str);
	} else if ([name hasPrefix:@"testLargeSet"]) {
		DPTestAssert([str isEqualToString:@"9999"], @"The returned string is not equal to '9999'. Returned string = %@", str);
	} else {
		return [super verifyResult:str ofTest:sel];
	}
	
	return YES;
}

@end
